package com.littleu.market.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.littleu.market.common.enumeration.GroupLevelEnum;
import com.littleu.market.mapper.GroupMapper;
import com.littleu.market.model.GroupDO;
import com.littleu.market.service.IGroupService;

public class GroupServiceImpl extends ServiceImpl<GroupMapper, GroupDO> implements IGroupService {
    @Override
    public Integer getParticularGroupIdByLevel(GroupLevelEnum level) {
        GroupDO groupDO = this.getParticularGroupByLevel(level);
        return groupDO == null ? 0 : groupDO.getId();
    }

    @Override
    public GroupDO getParticularGroupByLevel(GroupLevelEnum level) {
        if(GroupLevelEnum.USER == level){
            return null;
        }else{
            QueryWrapper<GroupDO> wrapper = new QueryWrapper();
            wrapper.lambda().eq(GroupDO::getLevel, level.getValue());
            GroupDO groupDO = this.baseMapper.selectOne(wrapper);
            return groupDO;
        }
    }
}
